package cn.seecoder.courselearning.controller.post;

import cn.seecoder.courselearning.service.post.PostService;
import cn.seecoder.courselearning.util.Constant;
import cn.seecoder.courselearning.vo.ResultVO;
import cn.seecoder.courselearning.vo.course.CourseVO;
import cn.seecoder.courselearning.vo.post.PostVO;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/post")
public class PostController {
    @Resource
    private PostService postService;

    /**
     * 根据分类标签，获取帖子列表
     * @param courseId 课程ID
     * @param type 课程类别
     */
    @GetMapping("/posts/type/{page}")
    public PageInfo<PostVO> getPostsByType(@RequestParam  Integer courseId,
                                               @RequestParam String type,
                                               @PathVariable Integer page) {
        return postService.getPostsByType(page, Constant.POST_PAGE_SIZE, courseId, type);
    }

    /**
     * 在某课程下创建帖子
     * @param post 帖子VO
     * @param courseId 课程id
     */
    @PostMapping("/{courseId}/postCreate")
    public ResultVO<PostVO> createPost(@RequestBody PostVO post, @PathVariable Integer courseId){
        return postService.createPost(post,courseId);
    }
}
